|
RAIS
3.2
|
00001 00028 using System; 00029 using System.Collections.Generic; 00030 using System.Data; 00031 using System.Text; 00032 using FieldTypes = System.Collections.Generic.Dictionary<string, RAIS.Common.TableManagement.Field.FieldTypeData>; 00033 using FieldSizes = System.Collections.Generic.Dictionary<string, RAIS.Common.TableManagement.Field.FieldSizeData>; 00034 using NecessityTypes = System.Collections.Generic.Dictionary<string, RAIS.Common.TableManagement.Field.NecessityTypeData>; 00035 00036 namespace RAIS.Common.TableManagement 00037 { 00041 public class Field : DBObject 00042 { 00043 //********************************************************************* 00044 #region Enumerators 00045 public enum FieldType 00046 { 00047 Text = 0, 00048 Date, 00049 Numeric, 00050 SingleLookup, 00051 MultipleLookup, 00052 LookupPlusIntegerValue, 00053 LookupPlusScientificValue, 00054 Link, 00055 Logical, 00056 Label 00057 } 00058 public enum NecessityType 00059 { 00060 Required = 0, 00061 Suggested, 00062 NotRequired 00063 } 00064 public enum FieldSize 00065 { 00066 Large = 0, 00067 Medium, 00068 Memo, 00069 Small, 00070 Integer, 00071 Rational, 00072 Scientific, 00073 TimeInterval, 00074 Year 00075 } 00076 #endregion 00077 //********************************************************************* 00078 #region Fields 00079 static FieldTypes fieldTypesDictionary; 00080 static FieldSizes fieldSizesDictionary; 00081 static NecessityTypes necessityTypesDictionary; 00082 00083 Table table; 00084 string localLanguageFieldName = ""; 00085 string fieldPurpose = ""; 00086 string localLanguageFieldPurpose = ""; 00087 FieldType fieldType; 00088 FieldSize? fieldSize; 00089 NecessityType necessityType; 00090 int order; 00091 bool isNameField = false; 00092 bool systemField = false; 00093 bool lockedField = false; 00094 00095 bool visibleOnForms = true; 00096 bool uniqueValue; 00097 bool needsTranslation = false; 00098 bool multiline; 00099 bool highField = false; 00100 bool readOnly = false; 00101 Table relatedTable; 00102 string queryName; 00103 int? parentFieldID = null; 00104 #endregion 00105 //********************************************************************* 00106 #region Properties 00107 static public FieldTypes FieldTypesDictionary 00108 { 00109 get { return fieldTypesDictionary; } 00110 set { fieldTypesDictionary = value; } 00111 } 00112 static public FieldSizes FieldSizesDictionary 00113 { 00114 get { return fieldSizesDictionary; } 00115 set { fieldSizesDictionary = value; } 00116 } 00117 static public NecessityTypes NecessityTypesDictionary 00118 { 00119 get { return necessityTypesDictionary; } 00120 set { necessityTypesDictionary = value; } 00121 } 00122 00123 public Table Table 00124 { 00125 get { return this.table; } 00126 set { this.table = value; } 00127 } 00128 public string LocalLanguageFieldName 00129 { 00130 get { return this.localLanguageFieldName; } 00131 set { localLanguageFieldName = value; } 00132 } 00133 public string FieldPurpose 00134 { 00135 get { return this.fieldPurpose; } 00136 set { fieldPurpose = value; } 00137 } 00138 public string LocalLanguageFieldPurpose 00139 { 00140 get { return this.localLanguageFieldPurpose; } 00141 set { localLanguageFieldPurpose = value; } 00142 } 00143 public FieldType Type 00144 { 00145 get { return this.fieldType; } 00146 } 00147 public FieldTypeData TypeData 00148 { 00149 get { return fieldTypesDictionary[this.TypeText]; } 00150 } 00151 public string TypeText 00152 { 00153 get 00154 { 00155 string result = ""; 00156 foreach (KeyValuePair<string, FieldTypeData> fieldTypeItem in fieldTypesDictionary) 00157 if (fieldTypeItem.Value.Type == this.fieldType) 00158 { 00159 result = fieldTypeItem.Value.VisibleName; 00160 break; 00161 } 00162 return result; 00163 } 00164 set 00165 { 00166 this.fieldType = fieldTypesDictionary[value].Type; 00167 this.fieldSize = null; 00168 } 00169 } 00170 public FieldSize? Size 00171 { 00172 get { return this.fieldSize; } 00173 } 00174 public FieldSizeData SizeData 00175 { 00176 get { return (this.fieldSize == null) ? null : fieldSizesDictionary[this.SizeText]; } 00177 } 00178 public string SizeText 00179 { 00180 get 00181 { 00182 string result = ""; 00183 foreach (KeyValuePair<string, FieldSizeData> fieldSizeItem in fieldSizesDictionary) 00184 if (fieldSizeItem.Value.Type == this.fieldSize) 00185 { 00186 result = fieldSizeItem.Value.VisibleName; 00187 break; 00188 } 00189 return result; 00190 } 00191 set 00192 { 00193 if (value == "") 00194 this.fieldSize = null; 00195 else 00196 this.fieldSize = fieldSizesDictionary[value].Type; 00197 } 00198 } 00199 public NecessityType Necessity 00200 { 00201 get { return this.necessityType; } 00202 } 00203 public NecessityTypeData NecessityData 00204 { 00205 get { return necessityTypesDictionary[this.NecessityText]; } 00206 } 00207 public string NecessityText 00208 { 00209 get 00210 { 00211 string result = ""; 00212 foreach (KeyValuePair<string, NecessityTypeData> necessityTypeItem in necessityTypesDictionary) 00213 if (necessityTypeItem.Value.Type == this.necessityType) 00214 { 00215 result = necessityTypeItem.Value.VisibleName; 00216 break; 00217 } 00218 return result; 00219 } 00220 set { this.necessityType = necessityTypesDictionary[value].Type; } 00221 } 00222 public int Order 00223 { 00224 get { return this.order; } 00225 set { this.order = value; } 00226 } 00227 public bool IsNameField 00228 { 00229 get { return this.isNameField; } 00230 set { this.isNameField = value; } 00231 } 00232 public bool SystemField 00233 { 00234 get { return this.systemField; } 00235 set { this.systemField = value; } 00236 } 00237 public bool LockedField 00238 { 00239 get { return this.lockedField; } 00240 set { this.lockedField = value; } 00241 } 00242 00243 public bool VisibleOnForms 00244 { 00245 get { return this.visibleOnForms; } 00246 set { this.visibleOnForms = value; } 00247 } 00248 public bool UniqueValue 00249 { 00250 get { return this.uniqueValue; } 00251 set { this.uniqueValue = value; } 00252 } 00253 public bool NeedsTranslation 00254 { 00255 get { return this.needsTranslation; } 00256 set { this.needsTranslation = value; } 00257 } 00258 public bool Multiline 00259 { 00260 get { return this.multiline; } 00261 set { this.multiline = value; } 00262 } 00263 00264 public bool HighField 00265 { 00266 get { return highField; } 00267 set { highField = value; } 00268 } 00269 public bool ReadOnly 00270 { 00271 get { return readOnly; } 00272 set { readOnly = value; } 00273 } 00274 public Table RelatedTable 00275 { 00276 get { return this.relatedTable; } 00277 set { this.relatedTable = value; } 00278 } 00279 public string ForeignKeyFieldName 00280 { 00281 get 00282 { 00283 if (this.RelatedTable == null) return ""; 00284 foreach (var field in Table.Fields.Values) 00285 { 00286 if (field.RelatedTable!=null && field.ID != ID && field.RelatedTable.ID == RelatedTable.ID) 00287 return string.Format("FK {0} ID", this.Name); 00288 } 00289 return string.Format("FK {0} ID", this.RelatedTable.Name); 00290 /*return (this.RelatedTable == null) 00291 ? "" 00292 : string.Format("FK {0} ID" 00293 , ((this.Type == FieldType.MultipleLookup) 00294 ? this.RelatedTable.Name 00295 : this.name)); */ 00296 } 00297 } 00298 public string QueryName 00299 { 00300 get { return this.queryName; } 00301 set { this.queryName = value; } 00302 } 00303 public string QueryNameWithoutParameters 00304 { 00305 get 00306 { 00307 int breacketIndex = this.queryName.IndexOf('('); 00308 00309 if (breacketIndex == -1) 00310 return this.queryName; 00311 else 00312 return this.queryName.Substring(0, breacketIndex); 00313 } 00314 } 00315 public int? ParentFieldID 00316 { 00317 get { return this.parentFieldID; } 00318 set { this.parentFieldID = value; } 00319 } 00320 public int MaxLength 00321 { 00322 get 00323 { 00324 if (this.fieldSize == Field.FieldSize.Small) 00325 return RAIS.Common.Constants.SMALL_FIELD_MAX_LENGTH; 00326 else if (this.fieldSize == Field.FieldSize.Medium) 00327 return RAIS.Common.Constants.MEDIUM_FIELD_MAX_LENGTH; 00328 else if (this.fieldSize == Field.FieldSize.Large) 00329 return RAIS.Common.Constants.LARGE_FIELD_MAX_LENGTH; 00330 else if (this.fieldSize == Field.FieldSize.Memo) 00331 return RAIS.Common.Constants.MEMO_FIELD_MAX_LENGTH; 00332 else 00333 return 0; 00334 } 00335 } 00336 public bool IsLookupField 00337 { 00338 get 00339 { 00340 if ((this.fieldType == FieldType.LookupPlusIntegerValue) 00341 || (this.fieldType == FieldType.LookupPlusScientificValue) 00342 || (this.fieldType == FieldType.SingleLookup) 00343 || (this.fieldType == FieldType.MultipleLookup) 00344 ) 00345 return true; 00346 else 00347 return false; 00348 } 00349 } 00350 public bool IsTextField 00351 { 00352 get 00353 { 00354 if (this.fieldType == FieldType.Text) 00355 return true; 00356 else 00357 return false; 00358 } 00359 } 00360 #endregion 00361 //********************************************************************* 00362 #region Constructors 00363 public Field() 00364 {} 00365 00366 public Field(IDataRecord record) 00367 { 00368 this.ID = (int)record["PK Field ID"]; 00369 this.Name = record["Field Name"].ToString(); 00370 this.localLanguageFieldName = record["Local Language Field Name"].ToString(); 00371 this.fieldPurpose = record["Field Purpose"].ToString(); 00372 this.localLanguageFieldPurpose = record["Local Language Field Purpose"].ToString(); 00373 this.fieldType = (FieldType)Enum.Parse(typeof(FieldType), record["Field Type Name"].ToString()); 00374 if (record["Field Size Name"] is DBNull) 00375 this.fieldSize = null; 00376 else 00377 this.fieldSize = (FieldSize)Enum.Parse(typeof(FieldSize), record["Field Size Name"].ToString()); 00378 this.necessityType = (NecessityType)Enum.Parse(typeof(NecessityType), record["Necessity Type Name"].ToString()); 00379 this.order = (int)record["Order"]; 00380 this.isNameField = (bool)record["Is Name Field"]; 00381 this.systemField = (bool)record["System Field"]; 00382 this.visibleOnForms = (bool)record["Visible On Forms"]; 00383 this.uniqueValue = (bool)record["Unique Value"]; 00384 this.needsTranslation = (bool)record["Needs Translation"]; 00385 this.multiline = (bool)record["Multiline"]; 00386 this.highField = (bool)record["High Field"]; 00387 this.readOnly = (bool)record["Read Only"]; 00388 this.lockedField = (bool)record["Locked"]; 00389 if (record["PK Table ID"].ToString() != "") 00390 this.RelatedTable = new Table(record); 00391 this.queryName = record["Field Query Name"].ToString(); 00392 if (!(record["FK Parent Field ID"] is DBNull)) 00393 this.parentFieldID = (int)record["FK Parent Field ID"]; 00394 } 00395 #endregion 00396 //********************************************************************* 00397 #region Nested classes 00398 public class FieldTypeData 00399 { 00400 //********************************************************************* 00401 #region Fields 00402 int id; 00403 string name; 00404 string visibleName; 00405 #endregion 00406 //********************************************************************* 00407 #region Properties 00408 public int ID 00409 { 00410 get { return this.id; } 00411 } 00412 public FieldType Type 00413 { 00414 get { return (FieldType)Enum.Parse(typeof(FieldType), this.name); } 00415 } 00416 public string VisibleName 00417 { 00418 get { return this.visibleName; } 00419 } 00420 #endregion 00421 //********************************************************************* 00422 #region Constructors 00423 public FieldTypeData() 00424 {} 00425 public FieldTypeData(IDataRecord record) 00426 { 00427 this.id = (int)record["PK Field Type ID"]; 00428 this.name = record["Field Type Name"].ToString(); 00429 this.visibleName = record["Field Type Visible Name"].ToString(); 00430 } 00431 #endregion 00432 } 00433 00434 public class FieldSizeData 00435 { 00436 //********************************************************************* 00437 #region Fields 00438 int id; 00439 string name; 00440 string visibleName; 00441 FieldType fieldType; 00442 #endregion 00443 //********************************************************************* 00444 #region Properties 00445 public int ID 00446 { 00447 get { return this.id; } 00448 } 00449 public FieldSize Type 00450 { 00451 get { return (FieldSize)Enum.Parse(typeof(FieldSize), this.name); } 00452 } 00453 public string VisibleName 00454 { 00455 get { return this.visibleName; } 00456 } 00457 public FieldType FieldType 00458 { 00459 get { return fieldType; } 00460 } 00461 #endregion 00462 //********************************************************************* 00463 #region Constructors 00464 public FieldSizeData() 00465 {} 00466 public FieldSizeData(IDataRecord record) 00467 { 00468 this.id = (int)record["PK Field Size ID"]; 00469 this.name = record["Field Size Name"].ToString(); 00470 this.visibleName = record["Field Size Visible Name"].ToString(); 00471 this.fieldType = (FieldType)Enum.Parse(typeof(FieldType), record["Field Type Name"].ToString()); 00472 } 00473 #endregion 00474 } 00475 00476 public class NecessityTypeData 00477 { 00478 //********************************************************************* 00479 #region Fields 00480 int id; 00481 string name; 00482 string visibleName; 00483 #endregion 00484 //********************************************************************* 00485 #region Properties 00486 public int ID 00487 { 00488 get { return this.id; } 00489 } 00490 public NecessityType Type 00491 { 00492 get { return (NecessityType)Enum.Parse(typeof(NecessityType), this.name); } 00493 } 00494 public string VisibleName 00495 { 00496 get { return this.visibleName; } 00497 } 00498 #endregion 00499 //********************************************************************* 00500 #region Constructors 00501 public NecessityTypeData() 00502 {} 00503 public NecessityTypeData(IDataRecord record) 00504 { 00505 this.id = (int)record["PK Necessity Type ID"]; 00506 this.name = record["Necessity Type Name"].ToString(); 00507 this.visibleName = record["Necessity Type Visible Name"].ToString(); 00508 } 00509 #endregion 00510 } 00511 #endregion 00512 } 00513 }